/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.server.modules.sys.web.im;

import com.server.common.web.BaseController;
import com.server.modules.api.service.IMService;
import com.server.modules.sys.entity.User;
import com.server.modules.sys.service.SystemService;
import com.server.modules.sys.service.im.ImService;
import com.server.modules.sys.utils.UserUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 普通用户信息Controller
 * @author 颜洪毅/傅友园
 * @version 2016-10-11
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/im")
public class ImController extends BaseController {
	@Resource
    protected IMService imService;
	
	@Resource
    protected SystemService systemService;
	
	@Resource
    protected ImService imService2;

	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list( HttpServletRequest request, HttpServletResponse response, Model model) {
		User user = UserUtils.getUser();
		model.addAttribute("user", user);
	return "/modules/sys/im/index";
	}
	
	//批量给以前创建的系统用户注册环信账号
	@RequestMapping(value = {"batchRegistUserHxAccount"})
	@ResponseBody
	public Object  batchRegistUserHxAccount( HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
		return imService2.batchRegisterUnHxUsers();
	}
	
	
	@RequestMapping(value = {"getChatRecordFromHx"})
	@ResponseBody
	public Object  getChatRecordFromHx( HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
		return imService2.getChatRecordFromHx();
	}
	
	@RequestMapping(value = {"getChatRecord"})
	@ResponseBody
	public Object  getChatRecord(String from) throws Exception {
		User user = UserUtils.getUser();
		String to=user.getHxUsername();
		return imService2.getChatRecordByToAndFrom(to, from);
	}


	

}